<script>
	import {userIsLogin, getCode, login ,uploadImages,updateUserInfo,insertPlugsPracticeStudent,searchPlugsPracticeSubjectList,updatePlugsPracticeStudent,checkPracticeStudentBindingState} from './utils/api.js';
	export default {
		onLaunch: function() {
		},
		onShow: function() {
			userIsLogin().then(sult=>{
				if(!sult.body.isLogin){
					let self = this;
					let token = uni.getStorageSync('userInfo').accessToken;
					let identification = '';
						uni.login({
							provider: 'weixin',
							success: function(wxs) {
								getCode({
									code: wxs.code
								}).then(res => {
									identification = res.body.openid;
									uni.setStorage({
										key: '__ddminiUserOpenid',
										data: identification
									});
									let user = {
										identification: identification,
									};
									let postData = `wechatServerJSON=${JSON.stringify(user)}`;
									login(postData).then(wes => {
										if (wes.code == 200) {
											uni.hideLoading();
											uni.setStorage({
												key: 'userInfo',
												data: wes.body
											});
											uni.setStorage({
												key: 'userId',
												data: wes.body.id
											});
										} else {
											uni.hideLoading();
											uni.showModal({
												title: '授权失败',
												content: wes.msg,
												showCancel: false
											});
										}
									});
									
								});
							}
						});
				}else{
					
				}
			})
			
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
